package com.surveypark.struts2.action;

import java.lang.reflect.ParameterizedType;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

public abstract class BaseAction<T> extends ActionSupport implements Preparable, ModelDriven<T> {

	private static final long serialVersionUID = -6497833467542670927L;
	
	public T model;
	
	@SuppressWarnings("unchecked")
	public BaseAction(){
		
		try {
			ParameterizedType type = (ParameterizedType)this.getClass().getGenericSuperclass();
			Class<T> clazz = (Class<T>)type.getActualTypeArguments()[0];
			model = clazz.newInstance();
		}  catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public T getModel() {
		// TODO Auto-generated method stub
		return model;
	}

	@Override
	public void prepare() throws Exception {
		// TODO Auto-generated method stub
		
	}

}
